/*******************************************************************************
 * Copyright (c) 2008-2009 zhang yuexiang.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package org.xfeep.alaya.orm.jpa.test;

import static org.junit.Assert.*;

import java.net.URL;


import org.junit.Test;
import org.xfeep.alaya.orm.jpa.PersistenceUnitInfoGroup;
import org.xfeep.alaya.orm.jpa.PersistenceUnitInfoImp;


public class PersistenceUnitInfoGroupXmlTestSet  {

	protected void setUp() throws Exception {
	}

	protected void tearDown() throws Exception {
	}
	
	@Test
	public void testParseSimpleXml() {
		PersistenceUnitInfoGroup pg = null;
		URL url = this.getClass().getResource("META-INF/persistence.xml");
		try {
			pg = PersistenceUnitInfoGroup.parse(url);
		} catch (Throwable e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
		assertEquals(2, pg.persistenceUnitInfoList.size());
		assertEquals("1.0", pg.version);
		
		PersistenceUnitInfoImp pui1 = pg.persistenceUnitInfoList.get(0);
		PersistenceUnitInfoImp pui2 = pg.persistenceUnitInfoList.get(1);
		
		assertEquals("OrderManagement", pui1.getPersistenceUnitName());
		assertEquals("OrderManagement2", pui2.getPersistenceUnitName());
		
		assertEquals("jdbc/MyOrderDB", pui1.jtaDataSourceName);
		assertEquals("jdbc/MyPartDB", pui2.jtaDataSourceName);
		
		assertEquals("META-INF/ormap.xml", pui1.getMappingFileNames().get(0));
		assertEquals("META-INF/ormap2.xml", pui2.getMappingFileNames().get(0));
		
		
		String urlString = url.toString().substring(0, url.toString().length() - "META-INF/persistence.xml".length());
		
		assertEquals(urlString + "MyOrderApp.jar", pui1.getJarFileUrls().get(0).toString());
		
		assertEquals("com.widgets.Customer", pui1.getManagedClassNames().get(1));
		assertEquals("FINE", pui2.getProperties().get("eclipselink.logging.level"));
		assertEquals("500", pui2.getProperties().get("eclipselink.cache.size.default"));
		
	}

}
